package tk.mybatis.springboot.common;

/**
 * @author
 */
public enum ErrorEnum {

    SUCCESS(0, "success"),

    //100-199



    //200-299



    //300-399


    //系统异常相关400-499
    SERVICE_EXCEPTION(400, "运行时异常"),



    //500-599
    PK_NOT_NULL(500,"主键ID不能为空"),
    PARAM_INVALIDATE(501,"参数非法"),


    //undefine错误信息
    UNDEFINE(-1, "未定义异常信息");

    private int code;
    private String msg;

    ErrorEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String msg(int code) {
        for (ErrorEnum m : ErrorEnum.values()) {
            if (m.getCode() == code) {
                return m.getMsg();
            }
        }
        return UNDEFINE.getMsg();
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static void main(String[] args) {
        System.out.println(ErrorEnum.msg(23));
    }
}
